﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
namespace DAO
{
    public class daoThong
    {
        DataProvider dp = new DataProvider();
        DataTable dt = new DataTable();
        public DataTable dLayDSNVLTuoiSong(string ngay)
        {
            string sql = "select p.MaPhieuYC,p.NVLapPhieuYC,p.NgayYeuCau,ctp.MaNL,ctp.SoLuongYC,nvl.DonVi,nvl.LoaiNL,nvl.SoLuongTon,nvl.TenNL,nvl.HanSuDung,nv.TenNV,nv.MaNV ";
            sql = sql + "from PhieuYeuCauNL p,CTPhieuYeuCauNL ctp ,NguyenVatLieu nvl, NhanVien nv ";
            sql = sql + "where p.MaPhieuYC=ctp.MaPhieuYC ";
            sql = sql + "and nv.MaNV=p.NVLapPhieuYC ";
            sql = sql + "and ctp.MaNL=nvl.MaNL ";
            sql = sql + "and p.NgayYeuCau=" + "'" + ngay + "' ";
            sql = sql + "and nvl.LoaiNL=0";
            return dt = dp.ExecuteQuery(sql);
        }
        public DataTable dLayDSNVLDaiHan(string ngay)
        {
            string sql = "select p.MaPhieuYC,p.NVLapPhieuYC,p.NgayYeuCau,ctp.MaNL,ctp.SoLuongYC,nvl.DonVi,nvl.LoaiNL,nvl.SoLuongTon,nvl.TenNL,nvl.HanSuDung,nv.TenNV ";
            sql = sql + "from PhieuYeuCauNL p,CTPhieuYeuCauNL ctp ,NguyenVatLieu nvl,NhanVien nv ";
            sql = sql + "where p.MaPhieuYC=ctp.MaPhieuYC ";
            sql = sql + "and nv.MaNV=p.NVLapPhieuYC ";
            sql = sql + "and ctp.MaNL=nvl.MaNL ";
            sql = sql + "and p.NgayYeuCau=" + "'" + ngay + "' ";
            sql = sql + "and nvl.LoaiNL=1";
            return dt = dp.ExecuteQuery(sql);
        }
        public bool ThemPhieuXuatKho(PhieuXuatKho dto)
        {
            string sql = "insert into PhieuXuatKho(NgayXuat,BepKiNhan,NVLapPhieuX,MaPYC)values('"+dto.NgayXuat+"',"+dto.BepKiNhan+","+dto.NVLapPhieu+","+dto.MaPYC+")";
            return dp.ExecuteNonQuery(sql);
        }
    }
}
